3 // Copyright (C) 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file tag_and_trait.hpp
38 * Contains tags and traits, e.g., ones describing underlying
42 #ifndef PB_DS_TAG_AND_TRAIT_HPP
43 #define PB_DS_TAG_AND_TRAIT_HPP
45 #include <ext/pb_ds/detail/type_utils.hpp>
48 * @namespace __gnu_pbds
49 * @brief GNU extensions for policy-based data structures for public use.
53 // A trivial iterator tag. Signifies that the iterators has none of
54 // the STL's movement abilities.
55 struct trivial_iterator_tag
58 // Prohibit moving trivial iterators.
59 typedef void trivial_iterator_difference_type;
62 // Signifies a basic invalidation guarantee that any iterator,
63 // pointer, or reference to a container object's mapped value type
64 // is valid as long as the container is not modified.
65 struct basic_invalidation_guarantee
68 // Signifies an invalidation guarantee that includes all those of
69 // its base, and additionally, that any point-type iterator,
70 // pointer, or reference to a container object's mapped value type
71 // is valid as long as its corresponding entry has not be erased,
72 // regardless of modifications to the container object.
73 struct point_invalidation_guarantee : public basic_invalidation_guarantee
76 // Signifies an invalidation guarantee that includes all those of
77 // its base, and additionally, that any range-type iterator
78 // (including the returns of begin() and end()) is in the correct
79 // relative positions to other range-type iterators as long as its
80 // corresponding entry has not be erased, regardless of
81 // modifications to the container object.
82 struct range_invalidation_guarantee : public point_invalidation_guarantee
86 /// A mapped-policy indicating that an associative container is a set.
87 // XXX should this be a trait of the form is_set<T> ??
88 struct null_mapped_type { };
91 /// Base data structure tag.
95 /// Basic string container, inclusive of strings, ropes, etc.
96 struct string_tag : public container_tag { };
99 struct sequence_tag : public container_tag { };
101 /// Basic associative-container.
102 struct associative_container_tag : public container_tag { };
105 struct basic_hash_tag : public associative_container_tag { };
107 /// Collision-chaining hash.
108 struct cc_hash_tag : public basic_hash_tag { };
110 /// General-probing hash.
111 struct gp_hash_tag : public basic_hash_tag { };
114 struct basic_tree_tag : public associative_container_tag { };
117 struct tree_tag : public basic_tree_tag { };
120 struct rb_tree_tag : public tree_tag { };
123 struct splay_tree_tag : public tree_tag { };
125 /// Ordered-vector tree.
126 struct ov_tree_tag : public tree_tag { };
129 struct trie_tag : public basic_tree_tag { };
132 struct pat_trie_tag : public trie_tag { };
135 struct list_update_tag : public associative_container_tag { };
137 /// Basic priority-queue.
138 struct priority_queue_tag : public container_tag { };
141 struct pairing_heap_tag : public priority_queue_tag { };
144 struct binomial_heap_tag : public priority_queue_tag { };
146 /// Redundant-counter binomial-heap.
147 struct rc_binomial_heap_tag : public priority_queue_tag { };
149 /// Binary-heap (array-based).
150 struct binary_heap_tag : public priority_queue_tag { };
153 struct thin_heap_tag : public priority_queue_tag { };
156 /// Base traits type for containers.
157 template<typename Tag>
158 struct container_traits_base;
161 struct container_traits_base<cc_hash_tag>
163 typedef cc_hash_tag container_category;
164 typedef point_invalidation_guarantee invalidation_guarantee;
168 order_preserving = false,
169 erase_can_throw = false,
170 split_join_can_throw = false,
171 reverse_iteration = false
176 struct container_traits_base<gp_hash_tag>
178 typedef gp_hash_tag container_category;
179 typedef basic_invalidation_guarantee invalidation_guarantee;
183 order_preserving = false,
184 erase_can_throw = false,
185 split_join_can_throw = false,
186 reverse_iteration = false
191 struct container_traits_base<rb_tree_tag>
193 typedef rb_tree_tag container_category;
194 typedef range_invalidation_guarantee invalidation_guarantee;
198 order_preserving = true,
199 erase_can_throw = false,
200 split_join_can_throw = false,
201 reverse_iteration = true
206 struct container_traits_base<splay_tree_tag>
208 typedef splay_tree_tag container_category;
209 typedef range_invalidation_guarantee invalidation_guarantee;
213 order_preserving = true,
214 erase_can_throw = false,
215 split_join_can_throw = false,
216 reverse_iteration = true
221 struct container_traits_base<ov_tree_tag>
223 typedef ov_tree_tag container_category;
224 typedef basic_invalidation_guarantee invalidation_guarantee;
228 order_preserving = true,
229 erase_can_throw = true,
230 split_join_can_throw = true,
231 reverse_iteration = false
236 struct container_traits_base<pat_trie_tag>
238 typedef pat_trie_tag container_category;
239 typedef range_invalidation_guarantee invalidation_guarantee;
243 order_preserving = true,
244 erase_can_throw = false,
245 split_join_can_throw = true,
246 reverse_iteration = true
251 struct container_traits_base<list_update_tag>
253 typedef list_update_tag container_category;
254 typedef point_invalidation_guarantee invalidation_guarantee;
258 order_preserving = false,
259 erase_can_throw = false,
260 split_join_can_throw = false,
261 reverse_iteration = false
267 struct container_traits_base<pairing_heap_tag>
269 typedef pairing_heap_tag container_category;
270 typedef point_invalidation_guarantee invalidation_guarantee;
274 order_preserving = false,
275 erase_can_throw = false,
276 split_join_can_throw = false,
277 reverse_iteration = false
282 struct container_traits_base<thin_heap_tag>
284 typedef thin_heap_tag container_category;
285 typedef point_invalidation_guarantee invalidation_guarantee;
289 order_preserving = false,
290 erase_can_throw = false,
291 split_join_can_throw = false,
292 reverse_iteration = false
297 struct container_traits_base<binomial_heap_tag>
299 typedef binomial_heap_tag container_category;
300 typedef point_invalidation_guarantee invalidation_guarantee;
304 order_preserving = false,
305 erase_can_throw = false,
306 split_join_can_throw = false,
307 reverse_iteration = false
312 struct container_traits_base<rc_binomial_heap_tag>
314 typedef rc_binomial_heap_tag container_category;
315 typedef point_invalidation_guarantee invalidation_guarantee;
319 order_preserving = false,
320 erase_can_throw = false,
321 split_join_can_throw = false,
322 reverse_iteration = false
327 struct container_traits_base<binary_heap_tag>
329 typedef binary_heap_tag container_category;
330 typedef basic_invalidation_guarantee invalidation_guarantee;
334 order_preserving = false,
335 erase_can_throw = false,
336 split_join_can_throw = true,
337 reverse_iteration = false
343 // See Matt Austern for the name, S. Meyers MEFC++ #2, others.
344 template<typename Cntnr>
345 struct container_traits
346 : public container_traits_base<typename Cntnr::container_category>
348 typedef Cntnr container_type;
349 typedef typename Cntnr::container_category container_category;
350 typedef container_traits_base<container_category> base_type;
351 typedef typename base_type::invalidation_guarantee invalidation_guarantee;
355 order_preserving = base_type::order_preserving,
356 erase_can_throw = base_type::erase_can_throw,
357 split_join_can_throw = base_type::split_join_can_throw,
358 reverse_iteration = base_type::reverse_iteration
361 } // namespace __gnu_pbds